package cn.yc.reader;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;

public class BufferedCopy_ {
    public static void main(String[] args) {
        String sourcePath = "e:\\io\\a.txt";
        String destPath = "e:\\io\\a_copy.txt";
        BufferedReader br = null;
        BufferedWriter bw = null;
        String line ;
        try {
            br =new BufferedReader(new FileReader(sourcePath));
            bw = new BufferedWriter(new FileWriter(destPath));
            while ((line=br.readLine())!=null){
                // readline 是读取一行写入一行，但是没有换行，所以要手动换行
                bw.write(line);
                bw.newLine();
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }finally {
            try {
                //关闭外层流
                if(br!=null)
                    br.close();
                if(bw!=null)
                    bw.close();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        /**
         * 注意：
         * BufferedReader或者BufferedWriter是按照字符操作，
         * 不要去操作二进制文件，可能会造成文件损坏
         */

    }
}
